home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2010 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: felix.teclink.net!usenet
  2. From: rad@teclink.net (rad)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Must I free my linked lists? (GCC)
  5. Date: 26 Jan 1996 02:45:25 GMT
  6. Organization: TECLink Internet Services: info@TECLink.Net
  7. Message-ID: <1875.6597T1319T164@teclink.net>
  8. References: <4dvn6t$lc3@hamilton.maths.tcd.ie>
  9. NNTP-Posting-Host: tc1_13.teclink.net
  10. X-Newsreader: THOR 2.22 (Amiga;TCP/IP) *UNREGISTERED*
  11.  
  12.  
  13. >rid@red-branch.MIT.EDU (Shawna Grimm) writes:
  14.  
  15. >>Unknown (Dannyman@uiuc.edu) typed in the following on 21 Jan 1996 22:09:16
  16. >>GMT:
  17. >>:    I'm writing a program that makes use of dynamic memory allocation
  18. >>:    through
  19. >>: linked lists using malloc() ... from an implementation PoV there's no need
  20. >>: to flush this stuff as after the queue is created it's output and the
  21. >>: program exits. My question is;
  22.  
  23. >>Yes, you _should_ free any memory that you allocate in your program.
  24. >>Memory that is allocated and not freed will not be returned to the system
  25. >>unless you turn the machine off, so if you want your memory back, you
  26. >>must free it. Personally, I would prefer to use AllocMem() or AllocVec()
  27. >>(with FreeMem() and FreeVec() ofcourse).
  28.  
  29. >I think the memory is freed in when you use malloc - in gcc or SAS/C.
  30. >Weither this is in malloc's spec is another matter. I think
  31. >memory you malloc ( as opposed to AllocMem'ed ) seems to be tracked
  32. >and freed at exit. I noticed this when I was testing something I was
  33. >writing on unix, and hadn't finished the memory stuff. It allocates
  34. >about 8MB, which went fine, but I was quite shoked to see that I could
  35. >run it twice in a row ( I only have 10MB of ram ).
  36.  
  37. Yes, ANSI-C compilers will track all memory allocated by malloc() calloc() and
  38. realloc() and free them on exiting the program.  It of course is better to
  39. free your own memory as you finish with so that if you start looping your code
  40. in the future you don't require gigabytes to run it.
  41.  
  42. --------------------------------------------------------------------------
  43. - Richard Deken                   E-Mail: (personal)     rad@teclink.net -
  44. - VLSI design engineer                    (AuE business) rad@aue.com     -
  45. - Advanced Microelectronics       PGP public key available               -
  46. --------------------------------------------------------------------------
  47.  
  48.